<template>
	<div>
		<div class="my-body_left_six">
			<div style="width: 100%; height: 50px; float: left; font-size: 26px;">企业名称管理</div>
			<div class="ipt_a">
				<div style="float: left; line-height: 30px;"  class="tab_font-size">企业名称：</div>
				<el-input v-model="input" placeholder="请输入内容"
					style=" width: 150px;height: 50px; float: left;"></el-input>
			</div>

			<el-button type="primary" plain>查询</el-button>

			<div style="margin-top: 30px;">
				<div>
					<el-button type="primary" @click="area = true" plain>添加</el-button>

					<el-button type="danger" @click="listdetl" plain>删除</el-button>

				</div>
				<el-dialog title="添加关联企业" :visible.sync="area" width="50%" :before-close="handleClose">
					<div style="width: 100%;">
						<el-form ref="form" :model="form" label-width="150px">
							<el-form-item label="企业编号">
								<el-input v-model="form.company_code" style="width:200px;"></el-input>
								<el-button type="primary">刷新</el-button>
							</el-form-item>
							
							<el-form-item label="企业名称">
								<el-input v-model="form.name" style="width:200px;"></el-input>
							</el-form-item>
							<el-form-item label="企业类型">
								 <el-checkbox-group v-model="is_jh" style="float: left;">
								      <el-checkbox label="1" checked >经销商</el-checkbox>
								   
								    </el-checkbox-group>
									<el-checkbox-group v-model="is_sq"  style="float: left; margin-left: 10px;">
										<el-checkbox label="1" checked>授权方</el-checkbox>
								   
								    </el-checkbox-group>
									<el-checkbox-group v-model="is_ps"  style="float: left; margin-left: 10px;">
										<el-checkbox label="1" checked >配送方</el-checkbox>
								   
								    </el-checkbox-group>
									
								     
								     
							</el-form-item>

							<el-form-item>
								<el-button type="primary" @click="onSubmit">保存</el-button>
								<el-button @click="handleClose">放弃</el-button>
							</el-form-item>
						</el-form>

					</div>
				</el-dialog>

				<template>
					<el-table :data="tableData" border style="width: 100%;  margin-top: 30px; overflow-y: auto;"
					   highlight-current-row  max-height="585"
    @current-change="handleCurrentChange" 
   :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
					>
						<!-- <el-table-column type="selection" width="55">
						</el-table-column> -->
						<el-table-column fixed prop="company_code" label="企业编号" >
						</el-table-column>
						<el-table-column fixed prop="name" label="企业名称">
						</el-table-column>
						<el-table-column prop="is_jh_txt" label="是否进货方">
						</el-table-column>
						<el-table-column prop="is_sq_txt" label="是否授权方">
						</el-table-column>
						<el-table-column prop="is_ps_txt" label="是否配送方">
						</el-table-column>
						<el-table-column prop="update_time" label="更新时间">
						</el-table-column>
                         <el-table-column prop="name" label="更新用户">
                         </el-table-column>
					</el-table>
				</template>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="currentPage" :page-sizes="[5, 10]" :page-size="pageSize"
								:total="tableData.length" layout="total, sizes, prev, pager, next, jumper">
							</el-pagination>
			</div>

		</div>
		<div class="my-body_left">
			<div style="width: 100%; height: 50px; float: left; font-size: 26px;">企业凭证</div>
			<div class="ipt_a">
				<el-button type="primary" @click="tablistya = true" plain>上传</el-button>
				<el-button plain>删除</el-button>
			</div>
			
			<template>
				<el-table :data="qiyelistlx" border style="width: 100%;margin-top: 30px;" :header-cell-style="{background:'#f5f7fa',color:'#606266'}">
					
					<el-table-column label="企业类型">
                           企业资质
					</el-table-column>
					<el-table-column  prop="file_name" label="资料名称">
					</el-table-column>
					<el-table-column prop="file_type_txt" label="资料类型">
					</el-table-column>
					
				</el-table>
			</template>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="currentPage" :page-sizes="[5, 10]" :page-size="pageSize"
								:total="qiyelistlx.length" layout="total, sizes, prev, pager, next, jumper">
							</el-pagination>
			<el-dialog title="添加资质备案文件(企业资质)" :visible.sync="tablistya" width="30%" :before-close="handleClose">
				<el-form ref="form" :model="form" label-width="150px">
            <el-form-item label="文件路径">
              <!-- 	<el-input v-model="form.name" style="width: 200px"></el-input> -->
              <el-upload
                :action="uploadUrl"
                list-type="text"
                :on-success="handleSuccess"
                :on-error="handleError"
              >
                <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>
            </el-form-item>

            <el-form-item label="文件名称">
              <el-input v-model="usernameimg" style="width: 200px"></el-input>
              <el-checkbox
                :indeterminate="isIndeterminate"
                v-model="checkAll"
                @change="handleCheckAllChange"
                >重命名</el-checkbox
              >
            </el-form-item>
            <el-form-item label="文件类型">
              <el-select v-model="usernamelei" placeholder="请选择文件类型">
                <el-option
                  v-for="item in shouquanlei"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id"
                  :disabled="item.disabled"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="onSubmitssqf">申请</el-button>
              <el-button @click="quxiaosq">取消</el-button>
            </el-form-item>
          </el-form>
			</el-dialog>
		</div>
	</div>
</template>

<script>
import { getData, postData } from "@/utils/request.js";
export default {
  data() {
    return {
      area: false,
      tjjfsq: false,
      tablisty: false,
      tablistya: false,
      tablistyb: false,
      areatinajia: false,
      key: 1, // 为了能每次切换权限的时候重新初始化指令
      options: [
        {
          value: "1",
          label: "全部",
        },
        {
          value: "2",
          label: "一般订单",
        },
        {
          value: "3",
          label: "积分订单",
        },
        {
          value: "3",
          label: "样品订单",
        },
        {
          value: "3",
          label: "换货订单",
        },
      ],
      value1: "",
      value2: "",
      value3: "",
      form: {
        name: "",
        company_code: "",
        is_jh: 1,
        is_sq: 1,
        is_ps: 1,
      },
      is_jh: "",
      is_sq: "",
      is_ps: "",
      radio: "授权医院",
      value: "",
      tableData: [],
      data: [
        {
          label: "XXX省",
          children: [
            {
              label: "XXX市",
            },
            {
              label: "XXX市",
            },
            {
              label: "XXX市",
            },
            {
              label: "XXX市",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      checkAll: false,
      checkedCities: [],
      cities: ["上海", "北京", "广州", "深圳"],
      isIndeterminate: true,
      input: "",
	  qiyelistlx:[],
	  usernameimg:"",
	  url:'',
	  usernamelei:"",
	  uploadUrl: "http://192.168.3.184:8093/api/index/uploadFile",
      shouquanlei: [],
	  bgform: "",
      fileList: [],
    };
  },
  created() {
    this.listtab();
	this.shangcahun()
  },
  methods: {
	quxiaosq(){
      this.tablistya = false
	},
	onSubmitssqf(){
		var data = {
        type: 2,
        token: localStorage.getItem("token"),
        belong_id: this.ids,
        file_name: this.usernameimg,
        file_type: this.usernamelei,
		url:this.url
		
      };
      postData("index/addFile", data).then((res) => {
        console.log(res);
      });
	},
	shangcahun() {
      var data = {
        type: 2,
        token: localStorage.getItem("token"),
      };
      postData("index/fileParams", data).then((res) => {
        // 处理响应数据

        this.shouquanlei = res.data.file_type;
        this.usernamelei = res.data.file_type[1].id;

        console.log(this.shouquanlei);
      });
    },
	handleSuccess(response, file, fileList) {
      console.log("文件上传成功", file);

      this.usernameimg = this.shouquanlei[this.usernamelei].title + ".png";
	  this.url = response.data.file
    },
	handleError(err, file, fileList) {
      console.error("文件上传失败", err, file, fileList);
    },
    handleCurrentChange(val) {
      console.log(val);
      this.ids = val.id;
	  this.qiyezizlist()
    },
    qiyezizlist() {
      var data = {
		company_id:this.ids,
        token: localStorage.getItem("token"),
      };
      postData("company/getFiles", data).then((res) => {
		var name = res.data.length
		
		if(name == undefined){
			this.qiyelistlx = []
		}else{
			this.qiyelistlx = res.data
		}
      
      });
    },
    listdetl() {
      if (this.ids == "") {
        this.$message({
          message: "请选择你要删除的数据",
          type: "success",
        });
      } else {
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            var data = {
              ids: this.ids,
              token: localStorage.getItem("token"),
            };
            postData("company/del", data).then((res) => {
              if (res.code == 0) {
                console.log(res, 66666);
                this.$message({
                  message: "删除成功",
                  type: "success",
                });
                this.listtab();
              } else {
                this.$message.error(res.msg);
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      }
    },

    handleClose() {
      this.area = false;
      this.tablistya = false;
    },
    listtab() {
      var data = {
        token: localStorage.getItem("token"),
      };
      postData("company/indexList", data).then((res) => {
        this.tableData = res.data.data;
      });
    },
    onSubmit() {
      if (this.is_jh == false) {
        this.form.is_jh = "";
      } else if (this.is_sq == false) {
        this.form.is_sq = "";
      } else if (this.is_ps == false) {
        this.form.is_ps = "";
      }
      var data = {
        token: localStorage.getItem("token"),
        company_code: this.form.company_code,
        name: this.form.name,
        is_jh: this.form.is_jh,
        is_sq: this.form.is_sq,
        is_ps: this.form.is_ps,
      };
      postData("company/operation", data).then((res) => {
        if (res.code == 0) {
          console.log(res, 66666);
          this.$message({
            message: "添加成功",
            type: "success",
          });
          this.listtab();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    handleClick(row) {
      console.log(row);
    },
    handleCheckAllChange(val) {
      const cityOptions = ["上海", "北京", "广州", "深圳"];
      console.log(val);
      this.checkedCities = val ? cityOptions : [];

      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
  },
};
</script>

<style lang="scss" scoped>
.ipt_a {
  width: 300px;
  height: 50px;
  float: left;
}

.ipt_b {
  width: 450px;
  height: 50px;
  float: left;
}
.el-table{
		height: calc(100vh - 282px);
}
</style>